<?php
Class Category{
	static public function unlimitedForLevel($cate,$html='　　　',$pid=0,$level=0){
		$arr=array();
		foreach ($cate as $v) {
			if ($v['pid']==$pid) {
				$v['level']=$level+1;
				$v['html']=str_repeat($html, $level);
				$arr[]=$v;
				$arr=array_merge($arr,self::unlimitedForLevel($cate,$html,$v['id'],$v['level']));
			}
		}
		return $arr;
	}
	
	/**
	 * 递归重组信息
	 *
	 * @param unknown $node
	 *        	要重组的节点数组
	 * @param number $pid
	 *        	父级id
	 */
	static public function node_merge($node, $access = null, $pid = 0) {
		$arr = array ();
	
		foreach ( $node as $v ) {
			if (is_array ( $access )) {
					
				$v ['access'] = in_array ( $v ['id'], $access ) ? 1 : 0;
			}
			if ($v ['pid'] == $pid) {
				$v ['child'] = node_merge ( $node, $access, $v ['id'] );
				$arr [] = $v;
			}
		}
		return $arr;
	}
	
	static public function getParents($cate,$id){
		$arr=array();
		foreach ($cate as $v){
			if ($v['id']==$id) {
				$arr[]=$v;
				$arr=array_merge(self::getParents($cate, $v['pid']),$arr);
			}
		}
		return $arr;
	}
	
	static public function getChildren($cate,$pid){
		$arr=array();
		foreach ($cate as $v){
			if ($v['pid']==$pid) {
				$arr[]=$v;
				$arr=array_merge($arr,self::getChildren($cate,$v['id'] ));
			}
		}
		return $arr;
	}
}
?>